unit callbackfunctions;

interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls
  //----------------------------------------------------------------------------
  ,libavformat,libavformat_avio,libavutil_error,libavutil_file,libavutil_mem
  //,libavcodec,libavcodec_avfft,libavdevice,libavfilter,libavfilter_avcodec,
  //,libavfilter_buffersink,libavfilter_buffersrc,libavfilter_formats
  //,libavformat_url,libavutil,libavutil_audio_fifo,libavutil_avstring
  //,libavutil_bprint,libavutil_buffer,libavutil_channel_layout,libavutil_common
  //,libavutil_cpu,libavutil_dict,libavutil_eval,libavutil_fifo
  //,libavutil_frame,libavutil_imgutils,libavutil_log,libavutil_mathematics
  //,libavutil_md5,libavutil_opt,libavutil_parseutils,libavutil_pixdesc
  //,libavutil_pixfmt,libavutil_rational
  //,libavutil_timestamp,libswresample,libswscale,libavutil_samplefmt,libavutil_time
  //----------------------------------------------------------------------------
  ;

type
  Pbuffer_data = ^Tbuffer_data;
  Tbuffer_data = record
    ptr: PByte;
    size: Integer; //Cardinal; ///< size left in the buffer
  end;

  function read_packet(opaque: Pointer; buf: PByte; buf_size: Integer): Integer; cdecl;
  function write_packet(opaque: Pointer; buf: PByte; buf_size: Integer): Integer; cdecl;
  function seek(opaque: Pointer; offset: Int64; whence: Integer): Int64; cdecl;
  
implementation

function read_packet(opaque: Pointer; buf: PByte; buf_size: Integer): Integer;
var
  bd: Pbuffer_data;
begin
  bd := Pbuffer_data(opaque);
  if buf_size > bd.size then
    buf_size := bd.size;

  //Writeln(Format('ptr:%p size:%d', [bd.ptr, bd.size]));

  (* copy internal buffer data to buf *)
  Move(bd.ptr^, buf^, buf_size);
  Inc(bd.ptr, buf_size);
  Dec(bd.size, buf_size);

  Result := buf_size;
end;

function write_packet(opaque: Pointer; buf: PByte; buf_size: Integer): Integer;
begin

end;

function seek(opaque: Pointer; offset: Int64; whence: Integer): Int64;
begin

end;

end.
